import Vue from 'vue'
import Vuex from 'vuex'
// 引入菜单仓库
import menu from "./modules/menu"
//引入角色仓库
import role from "./modules/role"
//引入管理员仓库
import user from "./modules/user"
// 引入商品分类仓库
import cate from "./modules/cate"
// 引入轮播图仓库
import banner from "./modules/bannner"
// 引入商品规格仓库
import specs from "./modules/specsx"
// 引入商品管理仓库
import goods from "./modules/goods"
// 引入限时秒杀仓库
import seck from "./modules/seck"
// 引入会员管理仓库
import member from "./modules/member"
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    // 管理员信息
    userInfo: sessionStorage.getItem("userInfo") ? JSON.parse(sessionStorage.getItem("userInfo")) : []
  },
  mutations: {
    REQ_USERINFO(state, payload) {
      return state.userInfo = payload
    }
  },
  actions: {
    setUserInfo_Action({ commit }, payload) {
      // 将管理员信息存入本地进行持久化保存
      sessionStorage.setItem("userInfo", JSON.stringify(payload))
      commit("REQ_USERINFO", payload)
    }
  },
  getters: {
    getUser(state) {
      return state.userInfo
    }
  },
  modules: {
    menu,
    role,
    user,
    cate,
    banner,
    specs,
    goods,
    seck,
    member
  }
})
